<template>
    <div class="container">
        <div class="left">
            <div class="username">{{ userInfo.username }}</div>
            <div>
                <el-menu mode="vertical">
                    <el-menu-item
                        v-for="item in settings"
                        :key="item.id"
                        @click="
                            currentComponent = item.component;
                            currentLabel = item.label;
                        "
                        :index="item.index"
                        >{{ item.label }}</el-menu-item
                    >
                </el-menu>
            </div>
        </div>
        <div class="right">
            <div class="title">{{ currentLabel }}</div>
            <component :is="currentComponent"></component>
        </div>
    </div>
</template>

<script>
import store from "@/store";
import Info from "@/components/PersonalInfo/Info";
import Email from "@/components/PersonalInfo/Email";
import Password from "@/components/PersonalInfo/Password";

export default {
    name: "PersonalInfoView",
    components: {
        Info,
        Email,
        Password,
    },
    data() {
        return {
            currentComponent: "Info",
            currentLabel: "个人信息",
            userInfo: {},
            settings: [
                {
                    id: 1,
                    component: "Info",
                    index: "info",
                    label: "个人信息",
                },
                {
                    id: 2,
                    component: "Email",
                    index: "email",
                    label: "邮箱管理",
                },
                {
                    id: 3,
                    component: "Password",
                    index: "password",
                    label: "修改密码",
                },
            ],
        };
    },
    beforeMount() {
        this.userInfo = store.state.userInfo;
    },
};
</script>

<style lang="scss" scoped>
.container {
    display: flex;
    flex-direction: row;
    width: 90%;
    margin: 0 auto;

    .left {
        height: 100%;
        flex: 1;
        // border: 1px solid black;
        padding: 1rem;
        margin-right: 1rem;

        .username {
            background-color: #b3e5fc;
            color: #616161;
            font-size: 2rem;
            padding: 1rem 0;
            text-align: center;
        }
    }

    .right {
        flex: 3;
        // border: 1px solid black;
        padding: 1rem;
        display: flex;
        flex-direction: column;

        .title {
            font-weight: bold;
            font-size: 1.2rem;
            padding: 1.2rem;
            margin-bottom: 1rem;
        }
    }
}
</style>
